package com.cj.cms.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.cj.cms.entity.LeaveWord;
import com.cj.cms.service.LeaveWordManager;
import com.cj.common.orm.Page;
import com.cj.common.orm.PropertyFilter;
import com.cj.common.orm.PropertyFilter.MatchType;
import com.cj.common.orm.hibernate.HibernateWebUtils;
import com.cj.common.web.struts2.Struts2Utils;

public class LeaveWordWebAction extends BaseWebAction{
	@Autowired
	private LeaveWordManager leaveWordManager;
	
	protected Page<LeaveWord> page = new Page<LeaveWord>(25,"createTime",Page.DESC);
	
	private LeaveWord leaveWord;
	
	private String leaveWordTitle;
	public String save(){
		try {
			if(leaveWord != null)
				leaveWordManager.save(leaveWord);
			return list();
		} catch (Exception e) {
			setErrMessage(e.getMessage(), e);
			return ERROR;
		}
	}
	
	public String list(){
		try {
			HttpServletRequest request = Struts2Utils.getRequest();
			List<PropertyFilter> filters = HibernateWebUtils.buildPropertyFilters(request);
			filters.add(new PropertyFilter("isOpen",1, MatchType.EQ));
			filters.add(new PropertyFilter("status",1, MatchType.EQ));
			page = leaveWordManager.search(page, filters);
			return SUCCESS;
		} catch (Exception e) {
			setErrMessage(e.getMessage(), e);
			return ERROR;
		}
	}
	public String add(){
		try {
			return INPUT;
		} catch (Exception e) {
			setErrMessage(e.getMessage(), e);
			return ERROR;
		}
	}

	public Page<LeaveWord> getPage() {
		return page;
	}

	public void setPage(Page<LeaveWord> page) {
		this.page = page;
	}

	public LeaveWord getLeaveWord() {
		return leaveWord;
	}

	public void setLeaveWord(LeaveWord leaveWord) {
		this.leaveWord = leaveWord;
	}

	public String getLeaveWordTitle() {
		return leaveWordTitle;
	}

	public void setLeaveWordTitle(String leaveWordTitle) {
		this.leaveWordTitle = leaveWordTitle;
	}
	
}
